﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OpenTKLightingTool.Helper
{
    /// <summary>
    /// Parsing helper class
    /// </summary>
    internal class Parse
    {
        public static float ParseFloat(string valueS)
        {
            float value;
            Parse.ParseFloat(valueS, out value);
            return value;
        }

        /// <summary>
        /// Parses float number
        /// </summary>
        public static bool ParseFloat(string valueS, out float value)
        {
            value = 0f;

            // try the system culture
            try
            {
                value = Convert.ToSingle(valueS, System.Threading.Thread.CurrentThread.CurrentUICulture.NumberFormat);
                return true;
            }
            catch
            {
            }

            // try en-US culture
            try
            {
                value = Convert.ToSingle(valueS, System.Globalization.CultureInfo.GetCultureInfo("en-US").NumberFormat);
                return true;
            }
            catch
            {
            }

            return false;
        }
    }
}
